/**
 *Create time: 2023-03-31 16:13
 *Author: Andy
 *Description: 二维码展示页面
 */
package com.andy.nature.ui.activity

import com.andy.common.base.BaseVMActivity
import com.andy.nature.databinding.ActivityQrcodeBinding
import com.andy.nature.vm.LoginViewModel
import com.andy.toast.extend.showNormalToast
import com.cloud.tmc.zxinglib.qrcode.QrCodeUtil
import dp

class QrCodeActivity : BaseVMActivity<ActivityQrcodeBinding, LoginViewModel>() {
    private var qrCodeWidth: Int = 264.dp
    private var qrCodeHeight: Int = 264.dp

    override fun initObserve() {
    }

    override fun initData() {
        showQrCode("http://www.baidu.com/")
    }

    override fun initAction() {
        mBinding?.apply {
            vTitle.setClickLeftCallBack {
                finish()
            }
        }
    }

    override fun viewModelClass(): Class<LoginViewModel> {
        return LoginViewModel::class.java
    }

    override fun getViewBinding(): ActivityQrcodeBinding {
        return ActivityQrcodeBinding.inflate(layoutInflater)
    }

    //展示二维码视图
    private fun showQrCode(inviteLink: String?) {
        if (inviteLink == null) {
            return
        }
        val qrBitmap = QrCodeUtil.createQRImage(qrCodeWidth, qrCodeHeight, inviteLink, null)
        mBinding?.ivQrcode?.setImageBitmap(qrBitmap)
    }
}